Objects and other items which are created or modified during execution of some piece of software can persist beyond the end of that execution if they are stored in a non-volatile medium, such as a flash memory or a hard drive. Object persistence is sometimes a topic of interest in persistent operating systems, or in software that utilizes object databases or object-relational mapping, for example. Although object-relational mapping software is used as a primary example herein, objects, persistence, fluency, API patterns, and other aspects of the discussion are sometimes relevant to other kinds of software, such as persistent operating systems that utilize objects.
An object-relational mapping can be used to convert data between an object model of an object-oriented program and a relational database. The mapping is performed, at least in part, by a tool known as an object-relational mapper. The acronym ORM is used herein to denote the mapping tool, the mapping itself, or both.
An ORM is useful because data in the object model is organized in non-scalar items, whereas data in the relational database is organized in scalar items. Integers, floating point values, and strings are examples of scalar values; structs, records, and object instances are examples of non-scalar values. An object model includes objects (class instances) which are frequently non-scalar values. In addition to multiple associated data values, an object may have associated methods, such as methods to set or get the data values or perform other operations. Many familiar database systems, including many structured query language database management systems, store and manipulate only scalar values, which are organized within tables. An ORM helps convert object values into groups of scalar values for persistent storage in the database, and convert those scalar values back into objects upon retrieval from the database. Thus, an ORM helps translate a logical representation of objects into a form that can be stored persistently in a relational database, without losing track of object properties and inter-relationships.